Ext.ns('Tm.category');
Tm.category.CategoryAddPanel = Ext.extend(Ext.Panel, {
			id : 'categoryAddPanel',
			frame : true,
			autoWidth : true,
			autoHeight : true,
			layout : 'fit',
			dataId : null,
			initComponent : function() {
				var dataId=this.dataId;
	

				
				var form = new Tm.common.FormPanel({
					frame : true,
					ref : 'form',

					defaults:{
					xtype : 'textfield',
					margins : '0 5 0 0',
					width : 300
					},			
					errorReader : new Tm.common.DataReader(),
					items : [ {
						name : 'id',
						hidden : true
					}, {
						xtype : 'googlesearchfield',
						fieldLabel : '所属父类',
						//allowBlank : false,
						name : 'parent',
						hiddenName : 'parent',
						queryURL : 'category/goolgeL1AndL2Category.do'
					}, {
						name : 'code',
						fieldLabel : '编码'
					} , {
						name : 'cnName',
						fieldLabel : '中文名称'
					}, {
						name : 'enName',
						fieldLabel : '英文名称'
					}, {
						name : 'description',
						fieldLabel : '描述',
						xtype : 'textarea'
					}]
				});
					
	

				var toolBar = new Ext.Toolbar({
					hideBorders : true,
					buttons : [{
								text : '保存',
								iconCls : 'act_acceptIcon',
								handler : function() {
									if (form.getForm().isValid()) {
										form.getForm().submit({
													waitMsg : '正在提交,请稍候...',
													url : 'category/saveOrUpdateCategory.do',
													method : 'POST',
													success : function(action, response) {
														App.setAlert('ok', '操作成功');
														var category = Ext.decode(response.response.responseText);
														var categoryAddPanel = Ext.getCmp("categoryAddPanel");
														var form = categoryAddPanel.form;

														categoryAddPanel.init(category,form);
													},
													failure : function(action, response) {
														App.setAlert('error', '操作失败');
													}
												});

									}
								}
							}, {
								xtype : 'tbseparator'
							}, {
								text : '重置',
								iconCls : 'act_resetIcon',
								handler : function() {
									form.getForm().reset();

								}
							} ]
				});

				Ext.apply(this, {
							tbar : toolBar,
							items : [form]
						});
				Tm.category.CategoryAddPanel.superclass.initComponent.call(this);
			},
			loadData : function() {
				var dataId = this.dataId;
				if (dataId) {
					Ext.Ajax.request({
						url : 'category/loadCategory.do',
						params : {
							id : dataId
						},
						success : function(response, action) {
							var category = Ext.decode(response.responseText);
							var categoryAddPanel = Ext.getCmp("categoryAddPanel");
							var form = categoryAddPanel.form;

							categoryAddPanel.init(category,form);


						
						},
						failure : function(response, action) {
							App.setAlert('error', '载入失败');
						}

					});
				}
			},
			init : function(category,form) {

				form.getForm().findField("id").setValue(category.id); 
				form.getForm().findField("parent").setValue(category.parent);
				form.getForm().findField("code").setValue(category.code);
				form.getForm().findField("enName").setValue(category.enName);
				form.getForm().findField("cnName").setValue(category.cnName);
				form.getForm().findField("description").setValue(category.description);

				
			},
			listeners : {
				render : function() {
					this.loadData();
				}
			}
		});
